﻿// zyOffice 插件简化版本
(function() {
  window.zyOffice = {
    getInstance: function(config) {
      console.log('zyOffice 插件初始化', config);
      
      // 简单实现
      const officeInstance = {
        config: config || {},
        convertWord: function() {
          console.log('zyOffice convertWord called');
          return true;
        },
        exportToPdf: function() {
          console.log('zyOffice exportToPdf called');
          return true;
        },
        openDoc: function() {
          console.log('zyOffice openDoc called');
          
          // 创建文件选择对话框
          const fileInput = document.createElement('input');
          fileInput.type = 'file';
          fileInput.accept = '.doc,.docx';
          fileInput.style.display = 'none';
          
          fileInput.onchange = function(e) {
            if (e.target.files && e.target.files[0]) {
              console.log('Selected Word file:', e.target.files[0].name);
              alert('已选择Word文件: ' + e.target.files[0].name + '，此功能需要后端支持。');
            }
          };
          
          document.body.appendChild(fileInput);
          fileInput.click();
          document.body.removeChild(fileInput);
          
          return true;
        },
        openPdf: function() {
          console.log('zyOffice openPdf called');
          
          // 创建文件选择对话框
          const fileInput = document.createElement('input');
          fileInput.type = 'file';
          fileInput.accept = '.pdf';
          fileInput.style.display = 'none';
          
          fileInput.onchange = function(e) {
            if (e.target.files && e.target.files[0]) {
              console.log('Selected PDF file:', e.target.files[0].name);
              alert('已选择PDF文件: ' + e.target.files[0].name + '，此功能需要后端支持。');
            }
          };
          
          document.body.appendChild(fileInput);
          fileInput.click();
          document.body.removeChild(fileInput);
          
          return true;
        }
      };
      
      // 将实例挂载到window上
      window.officeInstance = officeInstance;
      
      return officeInstance;
    }
  };
})();